"""
好物社用例
"""

from appium import webdriver
from time import  sleep
from  selenium.webdriver.common.by import By
import time

desired_capabilities={
    'platformName':'Android',
    'platformVersion':'7.1.2',
    'deviceName':'127.0.0.1:62001',
    'appPackage':'com.gfeng.daydaycook',
    'appActivity':'com.gfeng.daydaycook.activity.WelcomeActivity',
    'noReset':True,
    'newCommandTimeout':60,
    'unicodeKeyboard':True,
    'resetKeyboard':True
}
screen_name=time.strftime('%Y%m%d_%H%M%S')
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_capabilities)
driver.implicitly_wait(30)

#数据
shiping_name = '鲍'
#定位器
#好物社
hws_locator = (By.XPATH,'//android.widget.TabHost[@resource-id=\"android:id/tabhost\"]/android.widget.RelativeLayout[4]')
#输入框
srk_locator = (By.ID,'com.gfeng.daydaycook:id/qmuill_search')
input_locator = (By.ID,'searchInp')
#返回
back_locator = (By.ID,'com.gfeng.daydaycook:id/backButton')

#操作
#首页点击好物社
driver.find_element(*hws_locator).click()
sleep(2)
#点击输入框
driver.find_element(*srk_locator).click()
sleep(2)
#输入框输入关键字
driver.find_element(*input_locator).send_keys(shiping_name)
sleep(2)
#点击返回按钮
driver.find_element(*back_locator).click()
sleep(2)
#点击刷新
window_size = driver.get_window_size()
driver.swipe(window_size['width']/2,window_size['height']/3*2,window_size['width']/2,window_size['height']/3*1,1000)
sleep(2)